const totalCountInput = document.getElementById('totalCount');
const totalFeetInput = document.getElementById('totalFeet');
const calculateBtn = document.getElementById('calculateBtn');
const resultDiv = document.getElementById('result');

calculateBtn.addEventListener('click', () => {
    const totalCount = parseInt(totalCountInput.value);
    const totalFeet = parseInt(totalFeetInput.value);
    let chicken = -1;
    let rabbit = -1;
    let hasSolution = false;

    // 循环验证所有可能的鸡兔数量
    for (let i = 0; i <= totalCount; i++) {
        const j = totalCount - i; // 兔子数量 = 总数 - 鸡的数量
        if (2 * i + 4 * j === totalFeet) { // 鸡2只脚，兔4只脚
            chicken = i;
            rabbit = j;
            hasSolution = true;
            break;
        }
    }

    // 显示结果（有解/无解对应不同样式）
    if (hasSolution) {
        resultDiv.className = 'result success';
        resultDiv.textContent = `分别有鸡${chicken}只，有兔子${rabbit}只`;
    } else {
        resultDiv.className = 'result fail';
        resultDiv.textContent = '无解';
    }
});